home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 409 < prev    next >
Text File  |  1996-08-06  |  2KB  |  48 lines

  1. Path: lyra.csx.cam.ac.uk!nmm1
  2. From: nmm1@cus.cam.ac.uk (Nick Maclaren)
  3. Newsgroups: comp.std.c
  4. Subject: Re: CLOCKS_PER_SEC not defined
  5. Date: 16 Feb 1996 10:14:16 GMT
  6. Organization: University of Cambridge, England
  7. Message-ID: <4g1ldo$i2b@lyra.csx.cam.ac.uk>
  8. References: <ramin.1174728902A@news.gsfc.nasa.gov>
  9. NNTP-Posting-Host: ursa.cus.cam.ac.uk
  10.  
  11. In article <ramin.1174728902A@news.gsfc.nasa.gov>, ramin@twinkie.gsfc.nasa.gov (Ramin Sina) writes:
  12. |> Hello everyone,
  13. |> 
  14. |> I am using a supposedly ansi c program in which I write
  15. |> 
  16. |> #include <time.h>
  17. |> 
  18. |> #if defined(__STDC__) && !defined(CLOCKS_PER_SEC)
  19. |> #error "CLOCKS_PER_SEC is not defined on this stupid compiler"
  20. |> #endif
  21. |> 
  22. |> I get the error that CLOCKS_PER_SEC is not defined. I had thought that it
  23. |> was defined in standard C in the time.h header. I need CLOCKS_PER_SEC to
  24. |> time how long it takes for the program to run. Can anybody suggest how I can
  25. |> fix this problem.
  26.  
  27. You are probably using SunOS!  I recommend code like the following
  28. to fix up the problem.  Note that this will work on K&R C as well,
  29. which is why it doesn't use #elif.  If you hit a compiler without
  30. either CLOCKS_PER_SEC or CLK_TCK and other than 1000000 a second,
  31. you are in trouble :-(
  32.  
  33. #ifndef CLOCKS_PER_SEC
  34. #ifdef CLK_TCK
  35. #define CLOCKS_PER_SEC CLK_TCK   /* Some systems still use this older form */
  36. #endif
  37. #endif
  38. #ifndef CLOCKS_PER_SEC
  39. #define CLOCKS_PER_SEC 1000000   /* For non-ANSI systems, like SunOS! */
  40. #endif
  41.  
  42.  
  43. Nick Maclaren,
  44. University of Cambridge Computer Laboratory,
  45. New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
  46. Email:  nmm1@cam.ac.uk
  47. Tel.:  +44 1223 334761    Fax:  +44 1223 334679
  48.